﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.JinShengService;
using System.Collections.ObjectModel;
using CommunitySystem.Ctrls;

namespace CommunitySystem.PageView.晋升管理.新的晋升管理
{
    public partial class JSControl5 : UserControl
    {
        private JinShengService.JinShengServiceClient _client = null;
        private JinShengService.JinShen_ChooseCandidator_Main chooseMain = null;
        private JinShengService.JinShen_MainInfo _MainInfo = null;
        private ObservableCollection<JinShengService.JinShen_OKRenM_Detail> details = new ObservableCollection<JinShengService.JinShen_OKRenM_Detail>();


        public JSControl5(JinShen_MainInfo mainInfo, ObservableCollection<JinShengService.JinShen_OKRenM_Detail> _details)
        {
            InitializeComponent();
            _MainInfo = mainInfo;
          //  details.Clear();
            details = _details;
         
            LoadUI();
        }
      
        private bool CanEditInfo = true;

        private void LoadUI()
        {
            var des = details.Where(p => p.MainID == _MainInfo.ID).ToList();
            if (des != null && des.Count > 0)
            {
                TextBlock tb = new TextBlock() { Text = "科室:" + _MainInfo.Department, Margin = new Thickness(10, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center };
                selectionInfo.Children.Add(tb);
                tb = new TextBlock() { Text = "职位:" + _MainInfo.Position + "(" + _MainInfo.PositionLevel + ")", Margin = new Thickness(60, 0, 0, 0), VerticalAlignment = System.Windows.VerticalAlignment.Center };
                selectionInfo.Children.Add(tb);
            foreach (var d in des)
            {
                Border b = new Border() { BorderBrush = new SolidColorBrush(Colors.Blue), BorderThickness = new Thickness(1), Margin = new Thickness(5) };
                StackPanel sp = new StackPanel() { Margin = new Thickness(3), DataContext = d };
                b.Child = sp;
                StackPanel sp1 = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(3) };
                sp.Children.Add(sp1);

                var dgwxx = _MainInfo.DangGongWei_Detail.Where(p => p.MainID == d.MainID).Where(p => p.EmpID == d.EmpID).First();
                 tb = new TextBlock() { Text = "      ", Margin = new Thickness(0, 3, 0, 0) };
                sp1.Children.Add(tb);
                tb = new TextBlock() { Text = d.EmpName, Foreground = new SolidColorBrush(Colors.Blue) };
                sp1.Children.Add(tb);
                tb = new TextBlock() { Text = "同志任命为" };
                sp1.Children.Add(tb);
                tb = new TextBlock() { Text = _MainInfo.Department, Foreground = new SolidColorBrush(Colors.Blue) };
                //sp1.Children.Add(tb);
                //tb = new TextBlock() { Text = "科" };
                sp1.Children.Add(tb);
              //  tb = new TextBlock() { Text = _MainInfo.Position + "(" + _MainInfo.PositionLevel + ")", Foreground = new SolidColorBrush(Colors.Blue) };
                tb = new TextBlock() { Text = dgwxx.Position + "(" + dgwxx.AttributLevel + ")", Foreground = new SolidColorBrush(Colors.Blue) };
                sp1.Children.Add(tb);

                if (dgwxx.PositionAttibute == "领导职务")
                {
                    StackPanel sp3 = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(3) };
                    tb = new TextBlock() { Text = "任期自", Margin = new Thickness(0, 3, 0, 0) };
                    sp3.Children.Add(tb);
                    DatePicker dp = new DatePicker() { Margin = new Thickness(5, 0, 5, 0) };
                    dp.IsEnabled = CanEditInfo;
                    dp.SetBinding(DatePicker.SelectedDateProperty, new System.Windows.Data.Binding("StartDate") { Mode = System.Windows.Data.BindingMode.TwoWay, StringFormat = "yyyy-MM-dd" });
                    sp3.Children.Add(dp);
                    tb = new TextBlock() { Text = "到", Margin = new Thickness(0, 3, 0, 0) };
                    sp3.Children.Add(tb);
                    dp = new DatePicker() { Margin = new Thickness(5, 0, 5, 0) };
                    dp.IsEnabled = CanEditInfo;
                    dp.SetBinding(DatePicker.SelectedDateProperty, new System.Windows.Data.Binding("EndDate") { Mode = System.Windows.Data.BindingMode.TwoWay, StringFormat = "yyyy-MM-dd" });
                    sp3.Children.Add(dp);

                    StackPanel sp4 = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(3) };
                    tb = new TextBlock() { Text = "其中试用期", Margin = new Thickness(0, 3, 5, 0) };
                    TextBlock tbtb = new TextBlock() { Text = "年", Margin = new Thickness(0, 3, 5, 0) };
                    TextBox box1 = new TextBox() { Width = 60, Height = 25, DataContext = d };
                    box1.IsEnabled = CanEditInfo;
                    box1.SetBinding(TextBox.TextProperty, new System.Windows.Data.Binding("SYQYear") { Mode = System.Windows.Data.BindingMode.TwoWay });
                    sp4.Children.Add(tb);
                    sp4.Children.Add(box1);
                    sp4.Children.Add(tbtb);


                    sp.Children.Add(sp3);

                    sp.Children.Add(sp4);

                }
                else if (dgwxx.PositionAttibute == "非领导职务")
                {
                    StackPanel sp3 = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(3) };
                    tb = new TextBlock() { Text = "任命自", Margin = new Thickness(0, 3, 0, 0) };
                    sp3.Children.Add(tb);
                    DatePicker dp = new DatePicker() { Margin = new Thickness(5, 0, 5, 0) };
                    dp.IsEnabled = CanEditInfo;
                    dp.SetBinding(DatePicker.SelectedDateProperty, new System.Windows.Data.Binding("StartDate") { Mode = System.Windows.Data.BindingMode.TwoWay, StringFormat = "yyyy-MM-dd" });
                    sp3.Children.Add(dp);
                  
                    tb = new TextBlock() { Text = "起", Margin = new Thickness(0, 3, 0, 0) };
                    sp3.Children.Add(tb);

                    sp.Children.Add(sp3);

                }
                detailsInfo.Children.Add(b);
            }
            }
            else
                LayoutRoot.Visibility = Visibility.Collapsed;

        }

        void dcb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var dcb = sender as DictComboBox;
            var detail = dcb.DataContext as JinShengService.JinShen_DangGongWei_Detail;
            var sp = dcb.Tag as StackPanel;
            if (dcb.SelectedValue != null && dcb.SelectedValue.Equals("是"))
            {
                sp.Visibility = System.Windows.Visibility.Visible;
            }
            else if (dcb.SelectedValue != null && dcb.SelectedValue.Equals("否"))
            {
                sp.Visibility = System.Windows.Visibility.Collapsed;
                detail.ShiYongQiYear = 0;
            }
        }

      
    }
}
